package cn.bdqn.filter;

import javax.servlet.*;
import java.io.IOException;

public class EncodeFilter implements Filter {
    private String encode;
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        if(null==encode){
            encode=filterConfig.getInitParameter("encode");
        }
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        if(null==servletRequest.getCharacterEncoding()) {
            servletRequest.setCharacterEncoding(encode);
        }
        System.out.println("通过了字符过滤器。。。。。。。。。。。。。。。。。");
        //放行
        filterChain.doFilter(servletRequest,servletResponse);

    }

    @Override
    public void destroy() {

    }
}
